<?php
namespace App\Http\Controllers\ApiAdmin;

use App\Service\Admin\AdminService;
use Illuminate\Http\Request;

class LoginController extends BaseController
{
    //登录

    public function __construct(AdminService $service)
    {
        $this->db = $service;
    }

    //列表
    public function dologin(Request $request)
    {
        $uname = $request->post('uname', '');
        $upwd = $request->post('passwd', '');
        if (!preg_match('/^1[3-9]\d{9}$/', $uname)) {
            return $this->toJson(-2, '手机号格式错误');
        }
        if (strlen($upwd) < 6 || strlen($upwd) > 20) {
            return $this->toJson(-2, '密码必须6-20位之间');
        }
        $res = $this->db->dologin($uname, $upwd);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data']);
    }
}
